/**
 * @file
 * @author  michal.nezerka@gmail.com
 * @brief   Preferences Dialog Implemetation
 */

#include <iostream>
#include <wx/statbox.h>
#include <wx/stattext.h>
#include <wx/treebook.h>
#include <wx/valgen.h>

#include "preferencesdlg.h"

namespace wildwood 
{

BEGIN_EVENT_TABLE(PreferencesDlg, wxDialog)
    EVT_CLOSE(PreferencesDlg::OnClose)
END_EVENT_TABLE()

PreferencesDlg::PreferencesDlg(wxDialog *dlg, const wxString &title)
    : wxDialog(dlg, -1, title)
{
    SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);

    wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);

    // create buttons
    wxSizer* btnSizer = CreateButtonSizer(wxOK | wxCANCEL);

    wxNotebook* m_bookCtrl = new wxNotebook(this, wxID_ANY); //, wxDefaultPosition, wxDefaultSize, wxWS_EX_VALIDATE_RECURSIVELY);

    wxPanel* pageGeneral = CreateGeneralPage(m_bookCtrl);
    m_bookCtrl->AddPage(pageGeneral, _("General"), true);

    mainSizer->Add(m_bookCtrl, 0, wxALL | wxEXPAND, 5);

    // static line
    wxStaticLine * staticLine1 = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
    mainSizer->Add(staticLine1, 0, wxALL | wxEXPAND, 5);

    // sizing stuff
    mainSizer->Add(btnSizer, 0, wxALL, 3);

    this->SetSizer(mainSizer);
    this->Layout();
    mainSizer->Fit(this);
}

PreferencesDlg::~PreferencesDlg() { }

wxPanel* PreferencesDlg::CreateGeneralPage(wxWindow* parent)
{
    wxPanel* panel = new wxPanel(parent, wxID_ANY);
    wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );

    // root path
    wxStaticBox* rootPathStaticBox = new wxStaticBox(panel, wxID_ANY, _("TODO"));
    wxBoxSizer* rootPathStaticBoxSizer = new wxStaticBoxSizer(rootPathStaticBox, wxVERTICAL );
    topSizer->Add(rootPathStaticBoxSizer, 0, wxGROW|wxALL, 0);

    rootPathStaticBoxSizer->Add(new wxStaticText(panel, wxID_ANY, wxT("Song repository root path:")), 0, wxALL | wxEXPAND, 3);

    wxBoxSizer *rootPathSizer = new wxBoxSizer( wxHORIZONTAL );
    rootPathStaticBoxSizer->Add(rootPathSizer, 1, wxALL | wxEXPAND, 3);

    panel->SetSizer(topSizer);
    topSizer->Fit(panel);

    return panel;
}

void PreferencesDlg::OnClose(wxCloseEvent &event)
{
    Destroy();
}

bool PreferencesDlg::TransferDataToWindow()
{
    //m_editorColorText = wxGetApp().m_settings->m_editorColorText;
    //m_editorColorChords = wxGetApp().m_settings->m_editorColorChords;
    //m_editorColorCommands = wxGetApp().m_settings->m_editorColorCommands;

    bool result = wxDialog::TransferDataToWindow();

    //updateColors();

    return result;
}

bool PreferencesDlg::TransferDataFromWindow()
{
    bool result = wxDialog::TransferDataFromWindow();

    //wxGetApp().m_settings->m_editorColorText = m_editorColorText;
    //wxGetApp().m_settings->m_editorColorChords = m_editorColorChords;
    //wxGetApp().m_settings->m_editorColorCommands = m_editorColorCommands;

    return result;
}

} // namespace
